var express = require('express');
const { VirtualType } = require('mongoose');
var router = express.Router();
const userService = require('../service/userService');

router.get('/line',async function(req,res){
    let type = req.query.type;
    let users = await userService.find();
    // let now = new Date("2022/12/31");
    let now = new Date();
    let seriesData = [];
    let xAxisData = [];
    if(type == 30 || type == 60){
        // 查询近30或近60天数据
        for(let i = 0;i < type;i++){
            now.setDate(now.getDate() - 1);
            let length = users.filter(item => {
                // let d = new Date(item.createDate);
                let d = item.createDate;

                return now.getDate() == d.getDate() 
                        && now.getMonth() == d.getMonth() 
                        && now.getFullYear() == d.getFullYear();
            }).length;
            xAxisData.push((now.getMonth() + 1) + '/' + now.getDate());
            seriesData.push(length);
        }
    }else{
        // 查询近半年或1年数据
        for(let i = 0;i < type;i++){
            now.setMonth(now.getMonth() - 1);
            let length = users.filter(item => {
                // let d = new Date(item.createDate);
                let d = item.createDate;
                return now.getMonth() == d.getMonth() 
                    && now.getFullYear() == d.getFullYear();
            }).length;
            xAxisData.push((now.getMonth() + 1) + '月');
            seriesData.push(length);
        }
    }
   
    let data = {
        xAxisData,
        seriesData
    }
    res.send(data);
});
router.get('/bar',async function(req,res){
    let data = {
        xAxisData:["衬衫", "羊毛衫", "雪纺衫", "裤子", "高跟鞋", "袜子"],
        seriesData:[5, 20, 36, 10, 10, 20]
    }
    res.send(data);
});
router.get('/radar',async function(req,res){
    let data = {
        indicatorData:[
            {name: '亲情',max: 100},
            {name: '爱情',max: 100},
            {name: '友情',max: 100},
            {name: '热情',max: 100}
        ],
        seriesData:[
            {
                value: [5,25,87,68],
                name: "评测标题"
            }
        ]
    }
    res.send(data);
});
router.get('/area',async function(req,res){
    let data = [
        {
            value: 5000000,
            name: "衬衫",
        },
        {
            value: 822312,
            name: "羊毛衫",
        },
        {
            value: 3442212,
            name: "雪纺衫",
        },
        {
            value: 5512332,
            name: "裤子",
        },
        {
            value: 5512133,
            name: "高跟鞋",
        },
        {
            value: 2332131,
            name: "袜子",
        },
    ]
    res.send(data);
});

module.exports = router;